<template>
  <div id="spaceAnalyzePage">
    <h2>
      空间图库分析 -
      <span v-if="queryAll"> 全部空间 </span>
      <span v-else-if="queryPublic"> 公共图库 </span>
      <span v-else>
        <a :href="`/space/${spaceId}`" target="_blank">id：{{ spaceId }}</a>
      </span>
    </h2>
    <a-row :gutter="[16, 16]">
      <!-- 空间使用分析 -->
      <a-col :xs="24" :md="12">
        <SpaceUsageAnalyze :spaceId="spaceId" :queryAll="queryAll" :queryPublic="queryPublic" />
      </a-col>
      <!-- 空间分类分析 -->
      <a-col :xs="24" :md="12">
        <SpaceCategoryAnalyze :spaceId="spaceId" :queryAll="queryAll" :queryPublic="queryPublic" />
      </a-col>
      <!-- 标签分析 -->
      <a-col :xs="24" :md="12">
        <SpaceTagAnalyze :spaceId="spaceId" :queryAll="queryAll" :queryPublic="queryPublic" />
      </a-col>
      <!-- 图片大小分段分析 -->
      <a-col :xs="24" :md="12">
        <SpaceSizeAnalyze :spaceId="spaceId" :queryAll="queryAll" :queryPublic="queryPublic" />
      </a-col>
      <!-- 用户上传行为分析 -->
      <a-col :xs="24" :md="12">
        <SpaceUserAnalyze :spaceId="spaceId" :queryAll="queryAll" :queryPublic="queryPublic" />
      </a-col>
      <!-- 空间使用排行分析 -->
      <SpaceRankAnalyze
        v-if="isAdmin"
        :spaceId="spaceId"
        :queryAll="queryAll"
        :queryPublic="queryPublic"
      />
    </a-row>
  </div>
</template>

<script setup lang="ts">
import { useRoute } from 'vue-router'
import { computed } from 'vue'
import { useLoginUserStore } from '@/stores/useLoginUserStore.ts'
import SpaceRankAnalyze from '@/components/analyze/SpaceRankAnalyze.vue'
import SpaceUserAnalyze from '@/components/analyze/SpaceUserAnalyze.vue'
import SpaceSizeAnalyze from '@/components/analyze/SpaceSizeAnalyze.vue'
import SpaceTagAnalyze from '@/components/analyze/SpaceTagAnalyze.vue'
import SpaceCategoryAnalyze from '@/components/analyze/SpaceCategoryAnalyze.vue'
import SpaceUsageAnalyze from '@/components/analyze/SpaceUsageAnalyze.vue'
const route = useRoute()

// 空间 id
const spaceId = computed(() => {
  return route.query?.spaceId as string
})

// 是否查询所有空间
const queryAll = computed(() => {
  return !!route.query?.queryAll
})

// 是否查询公共空间
const queryPublic = computed(() => {
  return !!route.query?.queryPublic
})

const loginUserStore = useLoginUserStore()
const loginUser = loginUserStore.loginUser

const isAdmin = computed(() => {
  return loginUser.userRole === 'admin'
})
</script>

<style scoped>
/* 主容器升级 */
#spaceAnalyzePage {
  max-width: 1440px;
  margin: 0 auto;
  padding: 24px;
  background: linear-gradient(to bottom right, #f8f9fb 0%, #f1f3f6 100%);
  min-height: 100vh;
}

/* 标题区域美化 */
h2 {
  font-family: 'Avenir', Helvetica, Arial, sans-serif;
  font-size: 24px;
  color: #2c3e50;
  margin-bottom: 32px;
  padding: 16px 0;
  border-bottom: 2px solid rgba(66, 133, 244, 0.15);

  /* 渐变文字特效 */
  span {
    background: linear-gradient(45deg, #4285f4, #6c8ef5);
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
    font-weight: 600;
  }

  a {
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    &:hover {
      transform: translateY(-2px);
      text-shadow: 0 4px 12px rgba(66, 133, 244, 0.2);
    }
  }
}

/* 卡片容器增强 */
:deep(.ant-card) {
  border-radius: 12px !important;
  box-shadow: 0 6px 16px -8px rgba(31, 34, 37, 0.08),
  0 8px 28px -6px rgba(31, 34, 37, 0.05) !important;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  background: rgba(255, 255, 255, 0.95);
  border: none;

  &:hover {
    transform: translateY(-4px);
    box-shadow: 0 12px 24px -10px rgba(66, 133, 244, 0.2),
    0 8px 16px -6px rgba(66, 133, 244, 0.15) !important;
  }
}

/* 图表容器优化 */
:deep(.echarts) {
  min-height: 360px;
  transition: opacity 0.3s;

  /* 加载态处理 */
  &[data-loading="true"] {
    opacity: 0.3;
    filter: blur(2px);
  }
}

/* 响应式布局增强 */
@media (max-width: 768px) {
  #spaceAnalyzePage {
    padding: 16px;
  }

  :deep(.ant-col) {
    margin-bottom: 16px !important;
  }
}

/* 动态过渡效果 */
:deep(.ant-card-body) {
  > div {
    animation: fadeInUp 0.6s cubic-bezier(0.4, 0, 0.2, 1);
  }
}

@keyframes fadeInUp {
  from {
    opacity: 0;
    transform: translateY(20px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* 管理员专属样式 */
:deep(.admin-panel) {
  position: relative;
  &::before {
    content: "";
    position: absolute;
    top: -2px;
    left: -2px;
    right: -2px;
    bottom: -2px;
    border-radius: 14px;
    background: linear-gradient(135deg,
    rgba(66, 133, 244, 0.4) 0%,
    rgba(66, 133, 244, 0.2) 50%,
    rgba(66, 133, 244, 0.4) 100%);
    z-index: -1;
    animation: gradientFlow 3s ease infinite;
  }
}

@keyframes gradientFlow {
  0% { opacity: 0.6; }
  50% { opacity: 0.9; }
  100% { opacity: 0.6; }
}

/* 主容器升级为玻璃质感效果 */
#spaceAnalyzePage {
  max-width: 1600px;
  margin: 1rem auto;
  padding: 2rem 4rem;
  background: linear-gradient(135deg,
  rgba(248, 249, 251, 0.95) 0%,
  rgba(241, 243, 246, 0.92) 100%);
  backdrop-filter: blur(20px);
  border-radius: 2rem;
  box-shadow: 0 8px 32px rgba(31, 38, 135, 0.15);
  min-height: 100vh;
  border: 1px solid rgba(255,255,255,0.18);

  @media (max-width: 768px) {
    padding: 1.5rem;
    border-radius: 1.2rem;
  }
}

/* 标题区域升级 */
h2 {
  font-family: 'Inter', system-ui, sans-serif;
  font-size: 2.4rem;
  font-weight: 650;
  color: rgba(44, 62, 80, 0.9);
  margin-bottom: 3rem;
  padding: 1.5rem 0;
  position: relative;
  display: flex;
  align-items: center;
  gap: 1rem;

  &::after {
    content: "";
    position: absolute;
    bottom: 0;
    left: 0;
    width: 120px;
    height: 3px;
    background: linear-gradient(90deg, #4285f4 0%, #8a63d2 100%);
    border-radius: 2px;
  }

  span {
    background: linear-gradient(45deg, #4285f4, #8a63d2);
    -webkit-background-clip: text;
    background-clip: text;
    position: relative;
    padding-right: 2.4rem;

    &::after {
      content: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='24' height='24' viewBox='0 0 24 24'%3E%3Cpath fill='%234285f4' d='M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2m-1 17.93c-3.94-.49-7-3.85-7-7.93 0-.62.08-1.21.21-1.79L9 15v1c0 1.1.9 2 2 2v1.93m6.9-2.54c-.26-.81-1-1.39-1.9-1.39h-1v-3c0-.55-.45-1-1-1H8v-2h2c.55 0 1-.45 1-1V7h2c1.1 0 2-.9 2-2v-.41c2.93 1.19 5 4.06 5 7.41 0 2.08-.8 3.97-2.1 5.39'/%3E%3C/svg%3E");
      position: absolute;
      right: 0;
      top: 50%;
      transform: translateY(-45%);
      opacity: 0.8;
    }
  }

  a {
    position: relative;
    &::before {
      content: "";
      position: absolute;
      bottom: -2px;
      left: 0;
      width: 0;
      height: 2px;
      background: #4285f4;
      transition: width 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    }
    &:hover {
      transform: none;
      text-shadow: none;
      &::before {
        width: 100%;
      }
    }
  }
}

/* 卡片容器升级 */
:deep(.ant-card) {
  border-radius: 1.6rem !important;
  box-shadow:
    0 1.6rem 3.2rem -1.6rem rgba(31, 34, 37, 0.08),
    0 1.2rem 2.4rem -1.2rem rgba(66, 133, 244, 0.15) !important;
  background: rgba(255, 255, 255, 0.82);
  backdrop-filter: blur(12px);
  border: 1px solid rgba(255,255,255,0.3);
  overflow: hidden;

  &::before {
    content: "";
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(
      120deg,
      rgba(66, 133, 244, 0.05) 0%,
      rgba(255,255,255,0.15) 100%
    );
    pointer-events: none;
  }

  &:hover {
    transform: translateY(-6px) scale(1.02);
    box-shadow:
      0 2.4rem 4.8rem -1.6rem rgba(66, 133, 244, 0.25),
      0 1.6rem 3.2rem -1.2rem rgba(66, 133, 244, 0.2) !important;
  }

  .ant-card-head {
    border-bottom: 1px solid rgba(66, 133, 244, 0.15);
    background: rgba(255,255,255,0.3);
  }
}

/* 图表容器升级 */
:deep(.echarts) {
  min-height: 420px;
  margin: -1rem;

  &[data-loading="true"] {
    position: relative;
    &::after {
      content: "";
      position: absolute;
      top: 50%;
      left: 50%;
      width: 3rem;
      height: 3rem;
      border: 3px solid rgba(66, 133, 244, 0.2);
      border-top-color: #4285f4;
      border-radius: 50%;
      animation: spin 1s linear infinite;
    }
  }
}

@keyframes spin {
  to { transform: translate(-50%, -50%) rotate(360deg); }
}

/* 响应式布局增强 */
@media (max-width: 768px) {
  h2 {
    font-size: 1.8rem;
    flex-wrap: wrap;
  }

  :deep(.ant-col) {
    margin-bottom: 1.2rem !important;
  }
}



@keyframes cardEntrance {
  from {
    opacity: 0;
    transform: translateY(40px) scale(0.96);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

/* 管理员专属升级 */
:deep(.admin-panel) {
  position: relative;
  z-index: 1;

  &::before {
    animation: holographic 8s linear infinite;
    background: linear-gradient(
      135deg,
      rgba(66, 133, 244, 0.4) 0%,
      rgba(108, 142, 245, 0.3) 50%,
      rgba(66, 133, 244, 0.4) 100%
    );
    border-radius: 1.6rem;
  }

  &::after {
    content: "";
    position: absolute;
    top: -2px;
    left: -2px;
    right: -2px;
    bottom: -2px;
    background: linear-gradient(
      45deg,
      #4285f4 0%,
      #8a63d2 30%,
      #42b4f4 70%,
      #4285f4 100%
    );
    z-index: -2;
    opacity: 0.15;
    border-radius: 1.6rem;
    animation: gradientFlow 12s ease infinite;
  }
}

@keyframes holographic {
  0% { opacity: 0.6; }
  50% { opacity: 0.8; }
  100% { opacity: 0.6; }
}

/* 滚动联动动画 */
@media (prefers-reduced-motion: no-preference) {
  :deep(.ant-card) {
    transition:
      transform 0.6s cubic-bezier(0.22, 1, 0.36, 1),
      box-shadow 0.3s ease;
  }

  #spaceAnalyzePage {
    scroll-behavior: smooth;
  }
}
</style>
